# obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]
obstacleGrid=[[0],[1]]
def uniquePathsWithObstacles(obstacleGrid):
    gridRow=len(obstacleGrid)
    gridCol=len(obstacleGrid[0])
    dp=[[0 for _ in range(gridCol)] for _ in range(gridRow)]
    state_col=False
    for i in range(gridRow):
        for j in range(gridCol):
            if i==0:
                #第一行位置
                if obstacleGrid[i][j] == 1:
                    # 如果在第一行碰到了障碍物的话，那么后面的位置是不可能走的到的，取值为0
                    break
                dp[i][j]=1
            if j==0:
                #第一列位置
                if j==0 and obstacleGrid[i][j]==1:
                    state_col=True
                if j==0 and not state_col:
                    dp[i][j]=1
            if i>0 and i<gridRow and j>0 and j<gridCol:
                if obstacleGrid[i][j]==0:
                    #如果不是障碍物位置
                    dp[i][j]=dp[i-1][j]+dp[i][j-1]
                if obstacleGrid[i][j]==1:
                    dp[i][j]=0
    print(dp)
    return dp[gridRow-1][gridCol-1]
print(uniquePathsWithObstacles(obstacleGrid))